{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 根据SQL生成entity"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xlrd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "['Sheet1', 'Sheet2', 'Sheet3']"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "# 读取数据\n",
    "# 打开文件\n",
    "execl = xlrd.open_workbook('dbdata.xlsx')\n",
    "# 查看工作表\n",
    "execl.sheet_names()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "总行数：11\n总列数：14\n"
    }
   ],
   "source": [
    "# db = execl.sheet_by_name('Sheet1')\n",
    "db = execl.sheet_by_index(0)\n",
    "\n",
    "print(\"总行数：\" + str(db.nrows))\n",
    "print(\"总列数：\" + str(db.ncols))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "{'客户点价保证金ID': 'BAIL_ID', '收汇登记ID': 'RECEIPT_ID', '业务类型（认领、释放）': 'BILL_TYPE', '收款单号': 'RECEIPT_NO', '收款日期': 'RECEIPT_DATE', '收款金额': 'RECEIPT_AMT', '认领金额': 'CLAIM_AMT', '释放金额': 'RELEASED_AMT', '已释放金额': 'ALREADY_RELEASED_AMT', '币种': 'CURRENCY', '备注': 'REMARKS'}\n"
    }
   ],
   "source": [
    "dict = {}\n",
    "for rowNum in range(db.nrows):\n",
    "    rowVale = db.row_values(rowNum)\n",
    "    k = rowVale[6]\n",
    "    v = rowVale[0]\n",
    "    dict[k] = v\n",
    "print(dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def str2Hump(data):\n",
    "  arr = data.lower().split('_')\n",
    "  res = ''\n",
    "  j = 0\n",
    "  for i in arr:\n",
    "      if j == 0:\n",
    "          res = i\n",
    "      else:\n",
    "          res = res + i[0].upper() + i[1:]\n",
    "      j += 1\n",
    "  return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "/** \n* 客户点价保证金ID\n */ \n @ApiModelProperty(value = \"客户点价保证金ID\") \n private String bailId;\n/** \n* 收汇登记ID\n */ \n @ApiModelProperty(value = \"收汇登记ID\") \n private String receiptId;\n/** \n* 业务类型（认领、释放）\n */ \n @ApiModelProperty(value = \"业务类型（认领、释放）\") \n private String billType;\n/** \n* 收款单号\n */ \n @ApiModelProperty(value = \"收款单号\") \n private String receiptNo;\n/** \n* 收款日期\n */ \n @ApiModelProperty(value = \"收款日期\") \n private String receiptDate;\n/** \n* 收款金额\n */ \n @ApiModelProperty(value = \"收款金额\") \n private String receiptAmt;\n/** \n* 认领金额\n */ \n @ApiModelProperty(value = \"认领金额\") \n private String claimAmt;\n/** \n* 释放金额\n */ \n @ApiModelProperty(value = \"释放金额\") \n private String releasedAmt;\n/** \n* 已释放金额\n */ \n @ApiModelProperty(value = \"已释放金额\") \n private String alreadyReleasedAmt;\n/** \n* 币种\n */ \n @ApiModelProperty(value = \"币种\") \n private String currency;\n/** \n* 备注\n */ \n @ApiModelProperty(value = \"备注\") \n private String remarks;\n\n"
    }
   ],
   "source": [
    "ret = ''\n",
    "for (k,v) in dict.items():\n",
    "     ret += '/** \\n* ' + k + '\\n */ \\n @ApiModelProperty(value = \"' + k + '\") \\n private String ' + str2Hump(v) + ';\\n' \n",
    "print(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python37164bit8719ae96e4cc4b4bb775bda64dd4d4db",
   "display_name": "Python 3.7.1 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}